package com.cs2.volunteerpostbackend.web.controller;


import com.cs2.volunteerpostbackend.service.CommentService;
import com.cs2.volunteerpostbackend.service.ContentCheckService;
import com.cs2.volunteerpostbackend.web.dto.RespEntity;
import com.cs2.volunteerpostbackend.web.dto.comment.AddComment;
import com.cs2.volunteerpostbackend.web.vo.comment.CommentByPage;
import com.cs2.volunteerpostbackend.web.vo.comment.User2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
//@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;
    
    @Autowired
    private ContentCheckService contentCheckService;

    @PostMapping("/comment")
    public RespEntity addComment(@RequestBody AddComment comment) {
        // 内容检查
        if (contentCheckService.containsSensitiveContent(comment.getContent())) {
            return RespEntity.error("包含敏感值");
        }
        
        return commentService.addComment(comment) ? RespEntity.success("添加成功") : RespEntity.error("添加失败");
    }

    @DeleteMapping("/comment")
    public RespEntity delComment(String id) {

        return commentService.delComment(id) ? RespEntity.success("删除成功") : RespEntity.error("删除失败");
    }

    @GetMapping("/comment")
    public RespEntity getCommentsPages(String momentId, int page, int size) {
        if (momentId == null || momentId.trim().isEmpty()) {
            return RespEntity.error("momentId不能为空");
        }
        if (page < 1) page = 1;
        List<CommentByPage> commentByPages = commentService.getCommentPage(momentId, page, size);

        return RespEntity.success(commentByPages);
    }


}
